home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / SOUND / CRYS270.ZIP / CRYSDEV.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-06-26  |  5.2 KB  |  289 lines

  1. ;***************************************************************************
  2. ;*    Fonctions diverses utilisées par les différents drivers
  3. ;*
  4. ;* Programmé par Sébastien Granjoux
  5. ;* Commencé le 12/01/95
  6. ;* Modification le 12/01/95
  7.  
  8. IDEAL
  9. P386N
  10.  
  11. INCLUDE "CRYSERR.INC"
  12. INCLUDE "CRYSDEV.INC"
  13.  
  14. SEGMENT CODE PARA PUBLIC USE16 'CODE'
  15.  
  16. ASSUME cs:CODE,ds:CODE
  17.  
  18. ;*************************************************************************
  19. ;*    Calcul la table multiplication pour le volume
  20. ;*
  21. ;* Entrée:
  22. ;*    CL    nombre de voix utilisé
  23.  
  24. PROC    calvoltab
  25.  
  26.     mov    di,OFFSET VolumeTab    ;remplit la table de multiplication
  27.     xor    dl,dl
  28. @@fill_tab:
  29.     xor    dh,dh
  30. @@fill_line:
  31.     mov    al,dh
  32.     imul    dl
  33.     sar    ax,6
  34.     xor    ah,ah
  35.     add    al,128
  36.     div    cl
  37.     mov    [ds:di],al
  38.     inc    di
  39.     inc    dh
  40.     jne    @@fill_line
  41.     inc     dl
  42.     cmp    dl,64
  43.     jbe    @@fill_tab
  44.  
  45.     ret
  46. ENDP
  47.  
  48. ;*************************************************************************
  49. ;*    Calcul la table multiplication 8 bits optimal pour le volume
  50. ;*
  51. ;* Entrée:
  52. ;*    CL    nombre de voix utilisé
  53.  
  54. PROC    caloptvoltab
  55.  
  56.     mov    ch,cl
  57.     mov    cl,-1
  58.     mov    al,ch
  59. @@find_msbit:
  60.     inc    cl
  61.     shr    al,1
  62.     jne    @@find_msbit
  63.     mov    ax,100h
  64.     shl    ah,cl
  65.     xor    dx,dx
  66.     shr    cx,8
  67.     div    cx
  68.     mov    cx,ax
  69.  
  70.     mov    di,OFFSET VolumeTab    ;remplit la table de multiplication
  71.     xor    bl,bl
  72. @@fill_tab:
  73.     xor    bh,bh
  74. @@fill_line:
  75.     mov    al,bl
  76.     imul    bh
  77. ;    add    ax,31        ; Arrondie pour WP
  78.     sar    ax,6
  79. ;    cmp    ah,1
  80. ;    jne    @@no_overflow    ; Et sans débordement en plus !
  81. ;    mov    al,255
  82. ;@@no_overflow:
  83.     xor    ah,ah
  84.     add    al,128
  85.     mul    cx
  86.     mov    [ds:di],ah
  87.     inc    di
  88.     inc    bh
  89.     jne    @@fill_line
  90.     inc     bl
  91.     cmp    bl,64
  92.     jbe    @@fill_tab
  93.  
  94.     ret
  95. ENDP
  96.  
  97.  
  98. ;***************************************************************************
  99. ;*    Passe en mode fin d'interruption automatique
  100. ;*
  101.  
  102. PROC    setautoeoi
  103.  
  104.     mov    al,11h
  105.     out    20h,al
  106.     jmp    $+2
  107.     jmp    $+2
  108.     mov    al,8h
  109.     out    21h,al
  110.     jmp    $+2
  111.     jmp    $+2
  112.     mov    al,4h
  113.     out    21h,al
  114.     jmp    $+2
  115.     jmp    $+2
  116.     mov    al,3h
  117.     out    21h,al
  118.     jmp    $+2
  119.     jmp    $+2
  120.  
  121.     ret
  122.  
  123. ENDP
  124.  
  125. ;***************************************************************************
  126. ;*    Revient dans le mode fin d'interruption normale
  127.  
  128. PROC    reseteoi
  129.  
  130.     mov    al,11h
  131.     out    20h,al
  132.     jmp    $+2
  133.     jmp    $+2
  134.     mov    al,8h
  135.     out    21h,al
  136.     jmp    $+2
  137.     jmp    $+2
  138.     mov    al,4h
  139.     out    21h,al
  140.     jmp    $+2
  141.     jmp    $+2
  142.     mov    al,1h
  143.     out    21h,al
  144.     jmp    $+2
  145.     jmp    $+2
  146.  
  147.     ret
  148.  
  149. ENDP
  150.  
  151. ;***************************************************************************
  152. ;*    Change la vitesse en BPM
  153. ;*
  154. ;* Entrée:
  155. ;*    AL    nouvelle vitesse
  156.  
  157. PROC    defbpm
  158.  
  159.     movzx    cx,al
  160.     mov    ax,[MixRate]
  161.     mov    dx,25
  162.     mul    dx
  163.     div    cx
  164.     inc    ax
  165.     and    ax,0fffch
  166.     mov    [VoicesLen],ax
  167.     ret
  168.  
  169. ENDP
  170. ;***************************************************************************
  171. ;*    Recupère un l'octet courant du buffer
  172. ;*
  173. ;* Entrée:
  174. ;*    AL    numero de la voix
  175.  
  176. PROC    peekdef
  177.  
  178.     mov    ah,SIZE VOICE
  179.     mul    ah
  180.     mov    si,ax
  181.     add    si,OFFSET Voice1
  182.  
  183.     mov    dl,[(VOICE PTR ds:si).volume]
  184.     lds    edi,[(VOICE PTR ds:si).adrvoc]
  185.     mov    al,[ds:di]
  186.     mul    dl
  187.  
  188.     shr    ax,6
  189.     ret
  190.  
  191. ENDP
  192.  
  193. ;****************************************************************************
  194. ;*    Recupère l'adresse d'une interruption
  195. ;*
  196. ;* Entrée:
  197. ;*    BL    numero d'interruption
  198. ;*
  199. ;* Sortie:
  200. ;*    AX    offset de la routine d'interruption
  201. ;*    DX    segment de la routine d'interruption
  202.  
  203. PROC    getirq
  204.  
  205.     cmp    bl,8
  206.     jb    @@first_pic
  207.     add    bl,60h
  208. @@first_pic:
  209.     add    bl,8
  210.     xor    bh,bh
  211.     shl    bx,2
  212.     push    ds
  213.     xor    ax,ax
  214.     mov    ds,ax
  215.     mov     ax,[ds:bx]
  216.     mov    dx,[ds:bx+2]
  217.     pop    ds
  218.     ret
  219.  
  220. ENDP
  221.  
  222. ;*****************************************************************************
  223. ;*      Fixe un vecteur d'interruption (ATTENTION il faut avoir enlevé les
  224. ;*    interruption auparavant dans le programme principal)
  225. ;*
  226. ;* Entrée:
  227. ;*    BL    numero de l'irq
  228. ;*    DX:AX    adresse la routine sous interruption
  229.  
  230. PROC    setirq
  231.  
  232.     cmp    bl,8
  233.     jb    @@first_pic
  234.     add    bl,60h
  235. @@first_pic:
  236.     add    bl,8
  237.     xor    bh,bh
  238.     shl    bx,2
  239.     push    ds
  240.     push    ax
  241.     xor    ax,ax
  242.     mov    ds,ax
  243.     pop    ax
  244.     mov    [ds:bx],ax
  245.     mov    [ds:bx+2],dx
  246.     pop    ds
  247.     ret
  248.  
  249. ENDP
  250.  
  251. ;*************************************************************************
  252. ;*    Table d'amplification pour l'adlib et le speaker
  253.  
  254. AMPLI8            DB 40h,40h,40h,40h,40h,40h,40h,40h
  255.         DB 40h,40h,3fh,3fh,3fh,3fh,3fh,3fh
  256.         DB 3fh,3fh,3fh,3fh,3fh,3fh,3eh,3eh
  257.         DB 3eh,3eh,3eh,3eh,3eh,3eh,3eh,3eh
  258.         DB 3dh,3dh,3dh,3dh,3dh,3dh,3dh,3dh
  259.         DB 3dh,3ch,3ch,3ch,3ch,3ch,3ch,3ch
  260.         DB 3ch,3ch,3ch,3bh,3bh,3bh,3bh,3bh
  261.         DB 3bh,3bh,3bh,3bh,3bh,3ah,3ah,3ah
  262.         DB 3ah,3ah,3ah,3ah,3ah,3ah,3ah,39h
  263.         DB 39h,39h,39h,39h,39h,39h,39h,39h
  264.         DB 39h,38h,38h,38h,38h,38h,38h,38h
  265.         DB 38h,37h,37h,37h,37h,37h,36h,36h
  266.         DB 36h,36h,35h,35h,35h,35h,34h,34h
  267.         DB 34h,33h,33h,32h,32h,31h,31h,30h
  268.         DB 30h,2fh,2eh,2dh,2ch,2bh,2ah,29h
  269.         DB 28h,27h,26h,25h,24h,23h,22h,21h
  270.         DB 20h,1fh,1eh,1dh,1ch,1bh,1ah,19h
  271.         DB 18h,17h,16h,15h,14h,13h,12h,11h
  272.         DB 11h,10h,10h,0fh,0fh,0eh,0eh,0dh
  273.         DB 0dh,0dh,0ch,0ch,0ch,0ch,0bh,0bh
  274.         DB 0bh,0bh,0ah,0ah,0ah,0ah,0ah,09h
  275.         DB 09h,09h,09h,09h,09h,09h,09h,09h
  276.         DB 08h,08h,08h,08h,08h,08h,08h,08h
  277.         DB 08h,08h,08h,08h,07h,07h,07h,07h
  278.         DB 07h,07h,07h,06h,06h,06h,06h,06h
  279.         DB 06h,06h,06h,06h,06h,06h,05h,05h
  280.         DB 05h,05h,05h,05h,05h,05h,05h,05h
  281.         DB 04h,04h,04h,04h,04h,04h,04h,04h
  282.         DB 04h,04h,03h,03h,03h,03h,03h,03h
  283.         DB 03h,03h,03h,03h,02h,02h,02h,02h
  284.         DB 02h,02h,02h,02h,02h,01h,01h,01h
  285.         DB 01h,01h,01h,01h,01h,01h,01h,01h
  286.  
  287. ENDS
  288.  
  289. END